<?php

class Sistema_Form_Empresa extends Zend_Form
{

    public function init()
    {
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
                
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;
        
        $this->setName('form_'.$controller);
        $this->setAttrib('class', 'formCtrl');
                
        $el = new Zend_Form_Element_Hidden('EMP_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))
            ->addFilter('Int');
        $this->addElement($el);
        
        //$obj = new Sistema_Model_DbTable_Catsegmento();
        //$row = $obj->fetchAll('CTS_STA = 1')->toArray();
        $query = 'SELECT SQL_CACHE * FROM CATSEGMENTO WHERE CTS_STA = 1 ORDER BY CTS_ORD asc';
        $row = $db->fetchAll($query);
        $arr = array();
        foreach($row as $r) $arr[$r['CTS_ID']] = $r['CTS_NOM']; 
        
        $el = new Zend_Form_Element_Select('CTS_ID',array('onchange' => ''));
        $el->setLabel('Segmento')->setRequired(true)->addValidator('NotEmpty')->addMultiOptions($arr);
        $this->addElement($el);
        
        
        $el = new Zend_Form_Element_Text('EMP_NOM');
        $el->setLabel('Nome')
        ->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        $obj = new Sistema_Model_DbTable_Usuarios();
        $row = $obj->fetchAll()->toArray();
        $arr = array();
        foreach($row as $r) $arr[$r['USU_ID']] = $r['USU_NOME']; 
        
        $el = new Zend_Form_Element_Select('USU_ID',array('onchange' => ''));
        $el->setLabel('Usuário')->setRequired(true)->addValidator('NotEmpty')->addMultiOptions($arr);
        $this->addElement($el);
        
       
        $el = new Zend_Form_Element_File('EMP_FILE');
        $el->setLabel('Imagem - Tamanho: 900x300')
	->addValidator('Extension', false, array('jpg', 'png', 'gif'));
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Checkbox('EMP_STA',array('checked'=>'checked'));
        $el->setLabel('Status');
        $this->addElement($el);
        
        $btn = new Zend_Form_Element_Submit('submit',array('disableLoadDefaultDecorators' =>true));
        $btn->setLabel('Gravar');
        $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-button btn-ok');
        $this->addElement($btn);
        
        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        //$btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-button btn-cancel">Cancelar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-button btn-cancel');
        $this->addElement($btn);
        
    }


}

